<template>
  <div class="tableView innerView">
    
    <div class="m-layout-table">
      <div class="m-layout-table-search mt_10">
        <div class="m-layout-table-search-header"></div>
        <div class="m-layout-table-search-body">
          <div class="each">
            <el-input v-model="searchForm.one" placeholder="请输入内容"></el-input>
          </div>
           <div class="each">
            <el-input v-model="searchForm.one" placeholder="请输入内容"></el-input>
          </div>
           <div class="each">
            <el-input v-model="searchForm.one" placeholder="请输入内容"></el-input>
          </div>
           <div class="each">
            <el-input v-model="searchForm.one" placeholder="请输入内容"></el-input>
          </div>
        </div>

      </div>
       <div class="m-layout-table-tools mt_10">
        <el-button  type="primary" @click="loadTableData">搜索</el-button>
        <el-button  type="danger" @click="handlerDel">删除</el-button>

        <el-button  type="success">成功按钮</el-button>
        <el-button  type="info">信息按钮</el-button>
        <el-button  type="warning">警告按钮</el-button>
      </div>
      <div class="m-layout-table-main mt_10">
         <el-table
          :data="tableData"
          border
          stripe
         fit v-loading="tableLoading"

 @selection-change="handleSelectionChange"

          style="width: 100%">
          <el-table-column
            type="selection"
            width="36">
          </el-table-column>
          <el-table-column
            fixed
            prop="infoId"
            label="标识"
            width="100">
          </el-table-column>
          <el-table-column
            prop="infoTitle"
            label="名称">
          </el-table-column>
          <el-table-column
            prop="infoTime"
            label="时间"
            width="180">
          </el-table-column>
          <el-table-column
                fixed="right"
                label="操作"
                width="160">
                <template slot-scope="scope">
                  <el-button @click="handleClick(scope.row)" type="text" size="small">弹层编辑</el-button>
                  <el-button type="text" size="small" @click="handleEditClick(scope.row)" >跳转编辑页</el-button>
                </template>
            </el-table-column>
        </el-table>
      </div>
      <div class="m-layout-table-pager mt_10">
        <el-pagination
        ref="pagination_ref"
         @current-change="handlePageChange"
         @size-change="handleSizeChange"
          background
          layout="total,sizes,prev, pager, next ,jumper"

          :total="pager.totalCount">
        </el-pagination>
      </div>
    </div>


    <el-dialog
      title="编辑"
      :visible.sync="dialogVisible"
      width="60%"
      :before-close="handleClose">
      <Edit :id="eiditId" @dialog-close-emmit="dialogCloseEmmit" ></Edit>
    </el-dialog>

  </div>
</template>

<script>
import { PagerTest } from "../../service/UserSerice.js";

import Edit from "./Edit";
export default {
  name: "Table",
  data() {
    return {
      msg: "table",
      eiditId: 0,
      tableLoading: false,
      searchForm: {
        one: ""
      },
      pager: {
        pageIndex: 0,
        pageSize: 10,
        totalCount: 0
      },
      tableData: [],
      dialogVisible: false,
      multipleSelection: []
    };
  },
  mounted() {
    this.loadTableData();
  },
  methods: {
    getSearchParam() {
      var that = this;

      var param = {
        pageSize: that.pager.pageSize,
        pageIndex: that.pager.pageIndex
        //其它条件
      };
      return param;
    },
    loadTableData() {
      var that = this;
      var param = this.getSearchParam();
      console.log(param, "param");

      this.tableLoading = true;
      PagerTest(param).then(res => {
        this.tableLoading = false;

        that.pager.pageSize = res.resultData.pageSize;
        that.pager.totalCount = res.resultData.totalCount;

        console.log(res, "33333333333333");
        that.tableData = res.resultData.itemList;
      });
    },
    handleSizeChange(pageSize) {
      this.pager.pageSize = pageSize;
      console.log("当时页" + pageSize);
      this.loadTableData();
    },
    handlePageChange(pageIndex) {
      this.pager.pageIndex = pageIndex;
      this.loadTableData();
    },
    handleClick(row) {
      this.dialogVisible = true;
      this.eiditId = row.infoId;
      console.log(row);
    },
    handleEditClick(row) {
      var toPath = "/Demo/Edit";
      this.$router.push({
        //你需要接受路由的参数再跳转
        path: toPath,
        query: {
          id: row.infoId
        }
      });
    },
    handleClose() {
      this.dialogVisible = false;
    },
    editComfirm() {},
    handlerDel() {
      var selectedLen = this.multipleSelection.length;
      console.log(this.multipleSelection);
      if (selectedLen < 1) {
        this.$message({
          showClose: true,
          message: "请至少选择一条数据",
          type: "error",
          duration: 700
        });
        return false;
      }

      var infoIdArr = this._.pluck(this.multipleSelection, "infoId");

      alert(infoIdArr);
    },
    handleSelectionChange(rows) {
      console.log(rows, "handleSelectionChange");
      this.multipleSelection = rows;
    },
    dialogCloseEmmit() {
      this.dialogVisible = false;
      this.loadTableData();
      
    }
  },
  components: {
    Edit
  },
  activated(){
    this.loadTableData();
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style  lang="scss" scoped>
.innerView {
  margin: 0 auto;
}

.m-layout-table-search {
  height: 44px;
  line-height: 44px;
  // background-color: lightblue;
}

.m-layout-table-pager {
  height: 44px;
  line-height: 44px;
  background-color: white;
  vertical-align: middle;
  text-align: right;
  padding-right: 15px;
}

.m-layout-table-tools {
  height: 44px;
  line-height: 44px;
  background-color: white;
  padding: 0px 10px;
  // background-color: lightgreen;
}

.m-layout-table-search-body .each {
  width: 200px;
  float: left;
  margin-right: 10px;
}
</style>
